#include "mq_channal.hpp"
#include "mq_connection.hpp"
#include "mq_worker.hpp"
#include <memory>
#include <string>

int main()
{
    // 1、实例化异步工作线程池
    mq_zxws::AsyncWorker::ptr awp = std::make_shared<mq_zxws::AsyncWorker>();
    // 2、实例化connection对象
    mq_zxws::Connection::ptr conn = std::make_shared<mq_zxws::Connection>("127.0.0.1", 8080, awp);
    // 3、创建信道
    mq_zxws::Channal::ptr channal = conn->openChannal();
    // 4、通过信道提供的服务完成用户需求
    //   1）声明一个交换机exchange1，交换机类型为广播模式
    google::protobuf::Map<std::string, std::string> tmp;
    channal->declareExchange("exchange1", mq_zxws::ExchangeType::TOPIC, true, false, tmp);
    //   2）声明一个队列queue1
    channal->declareQueue("queue1", true, false, false, tmp);
    //   3）声明一个队列queue2
    channal->declareQueue("queue2", true, false, false, tmp);
    //   4）绑定queue1—exchange1，且binding_key设置为queue1
    channal->queueBind("exchange1", "queue1", "queue1");
    //   5）绑定queue2—exchange1，且binding_key设置为news.music.#
    channal->queueBind("exchange1", "queue2", "news.music.#");
    // 5、循环想交换机发送消息
    for(int i = 0; i < 10; i++){
        mq_zxws::BasicProperties bp;
        bp.set_id(mq_zxws::UUID::uuid());
        bp.set_deliver_mode(mq_zxws::DeliverMode::DURABLE);
        bp.set_routing_key("news.music.pop");
        channal->basicPublish("exchange1", &bp, "hello world-" + std::to_string(i));
    }
    mq_zxws::BasicProperties bp;
    bp.set_id(mq_zxws::UUID::uuid());
    bp.set_deliver_mode(mq_zxws::DeliverMode::DURABLE);
    bp.set_routing_key("news.music.sport");
    channal->basicPublish("exchange1", &bp, "hello sport");
    bp.set_routing_key("news.sport");
    channal->basicPublish("exchange1", &bp, "hello sport");
    // 6、关闭信道
    channal->closeChannal();
    return 0;
}